package org.ccay.web.support;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.shiro.authz.AuthorizationInfo;
import org.ccay.core.ioc.Ccay;
import org.ccay.core.request.IUserPrincipal;
import org.ccay.security.entity.Permission;
import org.ccay.security.entity.Program;
import org.ccay.security.entity.Role;
import org.ccay.sitemap.SiteNodeSimpleVO;

/**
 * 工作空间VO，本VO的作用在于将工作空间首页需要的各种信息一次性返回
 */
public class WorkspaceVO implements Serializable {

	private List<ServiceCacheVO> serviceCacheList;
	
	private Map<String, String> i18n;
	
    /**
     * 左菜单节点
     */
	private SiteNodeSimpleVO leftMenuNode;
	
	/**
	 * 范围角色信息
	 */
	protected Map<Program, LinkedHashSet<Role>> programRoles; 
	
	/**
	 * 权限信息
	 */
	protected Collection<String> permissions;


	public Map<String, String> getI18n() {
		return i18n;
	}

	public void setI18n(Map<String, String> i18n) {
		this.i18n = i18n;
	}

	public List<ServiceCacheVO> getServiceCacheList() {
		return serviceCacheList;
	}

	public void setServiceCacheList(List<ServiceCacheVO> serviceCacheList) {
		this.serviceCacheList = serviceCacheList;
	}

	public String getCurrentLanguage() {
		return currentLanguage;
	}

	public void setCurrentLanguage(String currentLanguage) {
		this.currentLanguage = currentLanguage;
	}

	public boolean isSwitchLanguageEnabled() {
		return switchLanguageEnabled;
	}

	public void setSwitchLanguageEnabled(boolean switchLanguageEnabled) {
		this.switchLanguageEnabled = switchLanguageEnabled;
	}

	public String[] getValidLanguages() {
		return validLanguages;
	}

	public void setValidLanguages(String[] validLanguages) {
		this.validLanguages = validLanguages;
	}

	public String getContextPath() {
		return contextPath;
	}
	public void setContextPath(String contextPath) {
		this.contextPath = contextPath;
	}

	public EnvironmentBean getEnvBean() {
		return envBean;
	}

	public void setEnvBean(EnvironmentBean envBean) {
		this.envBean = envBean;
	}

	/**
	 * @return the user
	 */
	public IUserPrincipal getUser() {
		return user;
	}

	public void setUser(IUserPrincipal user) {
		this.user = user;
	}
	
	public SiteNodeSimpleVO getLeftMenuNode() {
		return leftMenuNode;
	}
	public void setLeftMenuNode(SiteNodeSimpleVO leftMenuNode) {
		this.leftMenuNode = leftMenuNode;
	}

	private static final long serialVersionUID = 2816793440569511912L;
	
	/**
	 * 当前用户
	 */
	private IUserPrincipal user ;
	
	/**
	 * 环境敏感配置
	 */
	private EnvironmentBean envBean;
	
	/**
	 * 应用引入公共资源配置
	 */
	private List<AppResourceBean> appResBeans;
	
	/**
	 * 公共配置
	 */
	private Map<String, Serializable> config = new HashMap<String, Serializable>(); 
	/**
	 * @return
	 */
	public List<AppResourceBean> getAppResBeans() {
		return appResBeans;
	}

	/**
	 * @param appResBeans
	 */
	public void setAppResBeans(List<AppResourceBean> appResBeans) {
		this.appResBeans = appResBeans;
	}

	/**
	 * 上下文根
	 */
	private String contextPath;
	
	/**
	 * 是否语种切换
	 */
	private boolean switchLanguageEnabled;
	
	/**
	 * 有效语种，如 en_US,zh_CN 等形式形成的数组
	 */
	private String[] validLanguages;
	
	
	/**
	 * 用户当前语言
	 */
	private String currentLanguage;
	

	
	/**
	 * TODO 个性化配置集合
	 */
	//private List<PersonalizedSettingVO> userSettingList;
	
	
	/**
	 * TODO 用户界面动态提示配置集合
	 */
	//private List<HelperVO> helpers;
	
	/**
	 * TODO getHelpers
	 * @return
	 */
//	public List<HelperVO> getHelpers() {
//		return helpers;
//	}

	/**
	 * TODO setHelpers
	 * @param helpers
	 */
//	public void setHelpers(List<HelperVO> helpers) {
//		this.helpers = helpers;
//	}
	
	/**
	 * 是否打开消息推送
	 */
	private boolean pushMsg;
	
	public boolean isPushMsg() {
		return pushMsg;
	}

	public void setPushMsg(boolean pushMsg) {
		this.pushMsg = pushMsg;
	}

	/**
	 * 服务器时间
	 */
	private Date serverTime;
 

	public Date getServerTime() {
		return serverTime;
	}

	public void setServerTime(Date serverTime) {
		this.serverTime = serverTime;
	}
	public Map<Program, LinkedHashSet<Role>> getProgramRoles() {
		return programRoles;
	}

	public void setProgramRoles(Map<Program, LinkedHashSet<Role>> programRoles) {
		this.programRoles = programRoles;
	}

	public Collection<String> getPermissions() {
		return permissions;
	}

	public void setPermissions(Collection<String> permissions) {
		this.permissions = permissions;
	}
	
	/**
	 * globalScript,globalStyle 是否引入全局资源，默认不引入，需在数据中配置 
	 */
	private String globalScript;
	
	private String globalStyle;

	public String getGlobalScript() {
		return globalScript;
	}

	public void setGlobalScript(String globalScript) {
		this.globalScript = globalScript;
	}

	public String getGlobalStyle() {
		return globalStyle;
	}

	public void setGlobalStyle(String globalStyle) {
		this.globalStyle = globalStyle;
	}
	
	/**
	  *  检测浏览器标识
	 */
	private String checkBrowser;
	
	public String getCheckBrowser() {
		return checkBrowser;
	}

	public void setCheckBrowser(String checkBrowser) {
		this.checkBrowser = checkBrowser;
	}

	public Map<String, Serializable> getConfig() {
		return config;
	} 
	/**
	 * 内外网部署
	 */
	private String network;
	public String getNetwork() {
		return network;
	}

	public void setNetwork(String network) {
		this.network = network;
	}
	/**
	 * 当前主题名
	 */
	private String themeName;
	
	public String getThemeName() {
		return themeName;
	}

	public void setThemeName(String themeName) {
		this.themeName = themeName;
	}

	/**
	 * 是否开启主题切换开关
	 */
	private String switchThemeEnabled;
	
	public String getSwitchThemeEnabled() {
		return switchThemeEnabled;
	}
	public void setSwitchThemeEnabled(String switchThemeEnabled) {
		this.switchThemeEnabled = switchThemeEnabled;
	}
	
	/**
	 * @decription	主题名列表
	 */
	public Map<String, String> themes;

	/**
	 * @return
	 */
	public Map<String, String> getThemes() {
		Map<String, ThemeBean> themes = Ccay.getContext().getBeansOfType(ThemeBean.class);
		Map<String, String> themeNameList = new HashMap<String, String>();
		
		// 遍历主题,获得 {主题名:"name: 主题显示名 |^| imgUrl: 图片url"}
		for(String theme : themes.keySet()){
			//themeNameList.put(theme, themes.get(theme).getDisplayName()); 
			// |^|分隔符
			themeNameList.put(theme, "name:" + themes.get(theme).getDisplayName() + "|^|" + "imageUrl:" + themes.get(theme).getImageUrl()); 
		} 

		return themeNameList;
	}

	/**
	 * @param themes
	 */
	public void setThemes(Map<String, String> themes) {
		this.themes = themes;
	}
	
	/**
	 * 多语言列表
	 */
	private List<Map<String, String>> languageList;

	public List<Map<String, String>> getLanguageList() {
		return languageList;
	}

	public void setLanguageList(List<Map<String, String>> languageList) {
		this.languageList = languageList;
	}
	
}
